package cn.chencaiju.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;


public class LoginInterceptor implements HandlerInterceptor{
	Logger logger=LoggerFactory.getLogger(LoginInterceptor.class);
	@Override
	public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3)
			throws Exception {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView arg3)
			throws Exception {
		// TODO Auto-generated method stub
		
	}

	@Override
	public boolean preHandle(HttpServletRequest req, HttpServletResponse resp, Object arg2) throws Exception {
		
//		logger.info("controller 方法被拦截。。。");
//		HttpSession session = req.getSession();
//		String name = (String) session.getAttribute("name");
//		if(name==null||name.equals("")) {
//			logger.info("请登录");
//			req.getRequestDispatcher("/WEB-INF/pages/login.jsp").forward(req, resp);
//			return false;
//		}
//		logger.info("用户已登陆");
		return true;
	}

}
